package com.dongdongshop.util;

import org.quartz.*;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

@Component
public class JobExecute implements Job {

    @Resource
    private JavaMailUtils javaMailUtils;

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        //获取JobDetail中name和group
        JobKey key = context.getJobDetail().getKey();


        JobDataMap dataMap = context.getMergedJobDataMap();
        String name = dataMap.getString("name");
        String desc = dataMap.getString("desc");

        //定时执行尔维尼乌
        javaMailUtils.sendSimpleMail(desc,"感谢谢，大吉大利",name);
        System.out.println(new Date() + " : 定时任务执行...");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.err.println("Instance " + key + " of DumbJob says: " + name + ", and val is: " + desc);
        System.out.println(new Date() + " : 定时任务结束...");
    }
}
